package treeedit;

import java.util.ArrayList;

import javax.swing.JTree;
import javax.swing.tree.TreePath;

public class CodeModelExtra extends CodeModel
{
	protected Lisper lisper;
	
	public CodeModelExtra ( )
	{
		super();
		lisper = Lisper.getInstance();
	}
	
	@Override
	public Object getChild(Object parent, int index) 
	{
		CodeNode node = (CodeNode) parent;
//		System.err.println("Index " + index + " node "  + node.getCode() + " size " + node.getChildren().size());
		
		CodeNode p = (CodeNode) parent;
		if(p.isFunction())
		{
			return super.getChild(parent, index + 1);
		}
		else return super.getChild(parent, index);
	}

	@Override
	public int getChildCount(Object parent) {
	
		CodeNode p = (CodeNode) parent;
		int superCount = super.getChildCount(parent);
		
//		System.err.println(p.getRepresentation() + " " + p.getCode() + " " + superCount);
		
		if(p.getChildren().size() == 0) return 0;
		
		if(p.isFunction())
		{
//			System.err.println("**** FUNKCION " + (superCount -1));
			return superCount - 1; 
		}
		else 
		{
//			System.err.println("****  " + (superCount));
			return superCount;
		}

	}

	@Override	
	public int getIndexOfChild(Object parent, Object child) {
		CodeNode p = (CodeNode) parent;
		int index = super.getIndexOfChild(parent, child);


		if(p.isFunction())
		{	
			return index - 1;
		}
		return index;
	}

}
